package model

import (
	"encoding/json"
	"time"
)

const SysRoleTable = "sys_role"

type SysRole struct {
	Id             int       `gorm:"primaryKey;autoIncrement;comment:id"  json:"id"`
	RoleName       string    `json:"role_name" gorm:"column:role_name"`
	MenuPerm       string    `json:"menu_perm" gorm:"column:menu_perm"`
	NodePerm       string    `json:"node_perm" gorm:"column:node_perm"`
	RoleArea       string    `json:"role_area" gorm:"column:role_area"`
	Status         int       `json:"status" gorm:"column:status"`
	CreateUserName string    `json:"create_user_name" gorm:"column:create_user_name"`
	CreateTime     time.Time `json:"create_time" gorm:"column:create_time"`
	UpdateUserName string    `json:"update_user_name" gorm:"column:update_user_name"`
	UpdateTime     time.Time `json:"update_time" gorm:"column:update_time"`
}

func (r *SysRole) GetMenuPerm() []int {
	result := []int{}
	if len(r.MenuPerm) <= 2 {
		return result
	}
	_ = json.Unmarshal([]byte(r.MenuPerm), &result)
	return result
}

func (r *SysRole) GetNodePerm() []int {
	result := []int{}
	if len(r.NodePerm) <= 2 {
		return result
	}
	_ = json.Unmarshal([]byte(r.NodePerm), &result)
	return result
}

func (r *SysRole) GetRoleArea() []int {
	result := []int{}
	if len(r.RoleArea) <= 2 {
		return result
	}
	_ = json.Unmarshal([]byte(r.RoleArea), &result)
	return result
}
